package com.example.oasystem.service.impl;

import com.example.oasystem.dao.task.AoaTaskListDaoOfSun;
import com.example.oasystem.entity.status.AoaStatusList;
import com.example.oasystem.entity.task.AoaTaskListOfSun;
import com.example.oasystem.entity.task.AoaTaskLoggerOfSun;
import com.example.oasystem.entity.type.AoaTypeList;
import com.example.oasystem.entity.user.AoaUser;
import com.example.oasystem.service.AoaTaskListServiceOfSun;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class AoaTaskListServiceImplOfSun implements AoaTaskListServiceOfSun {

    @Autowired
    private AoaTaskListDaoOfSun aoaTaskListDaoOfSun;

    @Override
    public PageInfo<AoaTaskListOfSun> selectselectUserAllTask(int pageNum, int pageSize, String baseKey,long userId,long id) {
        PageHelper.startPage(pageNum,pageSize);
        List<AoaTaskListOfSun> aoaTaskListOfSuns = aoaTaskListDaoOfSun.selectselectUserAllTask(baseKey,userId,id);
        PageInfo<AoaTaskListOfSun> pageInfo = new PageInfo<>(aoaTaskListOfSuns);
        return pageInfo;
    }

    @Override
    public List<AoaTypeList> typeList() {
        return aoaTaskListDaoOfSun.typeList();
    }

    @Override
    public List<AoaStatusList> statusList() {
        return aoaTaskListDaoOfSun.statusList();
    }

    @Transactional
    @Override
    public void insertTask(AoaTaskListOfSun task,List<AoaUser> users) {
        aoaTaskListDaoOfSun.insertTask(task);
        aoaTaskListDaoOfSun.insertTaskUsers(task.getTaskId(),users);
    }

    @Override
    public List<AoaUser> selectUserIdAll(String[] split) {
        List<AoaUser> users=aoaTaskListDaoOfSun.selectUserIdAll(split);

        return users;
    }

    @Override
    public void updateTaskUser(AoaTaskListOfSun task) {

        aoaTaskListDaoOfSun.updateTaskUser(task);
    }

    @Transactional
    @Override
    public void updateTaskUserStatus(long taskId,List<AoaUser> users){
        aoaTaskListDaoOfSun.updateTaskUserStatus(taskId);
        aoaTaskListDaoOfSun.insertTaskUsers(taskId,users);
    }

    @Override
    public List<AoaTaskLoggerOfSun> selectLogger(int id) {
        return aoaTaskListDaoOfSun.selectLogger(id);
    }

    @Override
    public void updateTaskUserStatusId(long taskId, long loggerStatusid) {
        aoaTaskListDaoOfSun.updateTaskUserStatusId(taskId,loggerStatusid);
    }

    @Override
    public void addlogger(AoaTaskLoggerOfSun loggerOfSun) {
        aoaTaskListDaoOfSun.addlogger(loggerOfSun);
    }


    @Override
    public AoaTaskListOfSun selectOneTask(long id) {
        return aoaTaskListDaoOfSun.selectOneTask(id);
    }


}
